#pragma once
#include "Graph.hpp"

template<class T>
class UndirectedGraph : public Grapth
{
protected:
    void insert(int st, int ed, int w = INT32_MAX)
    {
        _head_arry[st]._data._v = st+1;
        auto cur = _head_arry[st]._firstarc;
        if(cur == nullptr)
        {
            auto tmp = new EdgeNode<Data<T>>(ed+1, w, nullptr);
            _head_arry[st]._firstarc = tmp;
        }
        else
        {
            auto prev = cur;
            while(cur != nullptr)
            {
                prev = cur;
                cur = cur->_next;
            }
            prev->_next = new EdgeNode<Data<T>>(ed+1, w, nullptr);
        }
    }
public:
    UndirectedGraph(int V, int E):Grapth(V, E)
    {}
    UndirectedGraph(const std::vector<std::vector<int>>& Admatrix)
    :Grapth()
    {
        for(int i = 0; i < _V; i++)
        {
            for(int j = 0; j < _V; j++)
            {
                if(Admatrix[i][j] == 1) insert(i, j);
            }
        }
    }
    virtual void Print() const
    {
        for(int i = 0; i < _V; i++)
        {
            std::cout << "顶点:" << i+1 << " --> ";
            auto cur = _head_arry[i]._firstarc;
            while(cur)
            {
                std::cout << "(" << i+1 << "," << cur->_data._v << ")" << "->";
            }
        }
    }
};


